home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12926 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: fred.net!news
  2. From: bitmask@bigdog.fred.net (Scott Allen)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Persistent Objects
  5. Date: Wed, 20 Mar 1996 12:55:32 GMT
  6. Organization: FredNet - Frederick, Md.
  7. Message-ID: <314f0632.13262854@news.fred.net>
  8. References: <4i50ja$2lu@atlantis.cc.uwf.edu> <4if2op$578@sam.inforamp.net>
  9. NNTP-Posting-Host: bitmask.fred.net
  10. X-Newsreader: Forte Agent .99d/32.168
  11.  
  12. rmorin@inforamp.net (Randy Charles Morin) wrote:
  13. >
  14. >class PersistentObject 
  15. >{
  16. >private:
  17. >    int i;
  18. >public:
  19. >    PersistentObject();
  20. >    ~PersistentObject();    
  21. >};
  22. >
  23. >PersistentObject::PersistentObject()
  24. >{
  25. >    ifstream is(FILENAME.EXT);
  26. >    is >> i;
  27. >}
  28. >
  29. >PersistentObject::~PersistentObject()
  30. >{
  31. >    ofstream os(FILENAME.EXT);
  32. >    os << i;
  33. >}
  34. >
  35. >A very simplistic example.
  36.  
  37. I just wanted to add to Randy's example a little bit.
  38.  
  39. A better implementation of a persistant object would 
  40. use the  chainable << and >> operators to allow 
  41. you to save your objects in a stream. You could then 
  42. steam multiple objects into a file on disk,
  43.  into memory, over a modem  etc. etc. 
  44.  
  45. The above code would have a little bit of problem
  46. if a class is instantiated more than once.
  47. --
  48.        Scott Allen             
  49.   bitmask@bigdog.fred.net      
  50.     Hagerstown, MD USA         
  51.